package com.lc.luzhengtang.activity;

import android.os.Bundle;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.text.TextUtils;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.lc.luzhengtang.R;
import com.lc.luzhengtang.adapter.CommentChangeAdapter;
import com.lc.luzhengtang.base.BaseActivity;
import com.lc.luzhengtang.bean.CommenBean;
import com.lc.luzhengtang.bean.CommentChangeBean;
import com.lc.luzhengtang.conn.Conn;
import com.lc.luzhengtang.conn.ConnCommentChange;
import com.lc.luzhengtang.conn.ConnSubmitCommentChange;
import com.lc.luzhengtang.util.LovelyToast;
import com.zcx.helper.http.AsyCallBack;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

import static com.lc.luzhengtang.R.id.layout_goodscomment;

/**
 * Created by Administrator on 2017/5/5.
 */
public class CommentChangeActivity extends BaseActivity {

    @BindView(R.id.img_news)
    ImageView imgNews;
    @BindView(R.id.textView6)
    TextView textView6;
    @BindView(R.id.img_shop)
    ImageView imgShop;
    @BindView(R.id.edit_comment)
    EditText editComment;
    @BindView(R.id.recyclerView_list)
    RecyclerView recyclerViewList;
    @BindView(R.id.img_checkbox_unselected)
    ImageView imgCheckboxUnselected;
    @BindView(R.id.btn_sendcomment)
    Button btnSendcomment;
    @BindView(layout_goodscomment)
    LinearLayout layoutGoodscomment;
    @BindView(R.id.layout_middel_comment)
    LinearLayout layoutMiddelComment;
    @BindView(R.id.layout_bad_comment)
    LinearLayout layoutBadComment;

    String comment_status = "3";
    @BindView(R.id.img_goods)
    ImageView imgGoods;
    @BindView(R.id.img_middle)
    ImageView imgMiddle;
    @BindView(R.id.img_bad)
    ImageView imgBad;
    CommentChangeAdapter mCommentChangeAdapter;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_comment_change);
        ButterKnife.bind(this);
        recyclerViewList.setLayoutManager(new GridLayoutManager(this, 4));
        getCommentChangeData();
    }

    public void getCommentChangeData() {
        new ConnCommentChange(getIntent().getStringExtra("evaluate_id"), new AsyCallBack<CommentChangeBean>() {
            @Override
            public void onStart(int type) throws Exception {
                super.onStart(type);
            }

            @Override
            public void onSuccess(String toast, int type, Object o, CommentChangeBean s) throws Exception {
                super.onSuccess(toast, type, o, s);
                Glide.with(CommentChangeActivity.this).load(Conn.HOST2 + getIntent().getStringExtra("img_url")).crossFade().error(R.mipmap.zhanwei).placeholder(R.mipmap.zhanwei).into(imgShop);
                mCommentChangeAdapter = new CommentChangeAdapter(s.getData().get(0).getPicarr());
                recyclerViewList.setAdapter(mCommentChangeAdapter);


            }

            @Override
            public void onFail(String toast, int type) throws Exception {
                super.onFail(toast, type);
            }

            @Override
            public void onEnd(String toast, int type) throws Exception {
                super.onEnd(toast, type);
            }
        }

        ).execute(CommentChangeActivity.this, false);
    }

    @OnClick({R.id.img_news, R.id.textView6, R.id.img_shop, R.id.edit_comment, R.id.img_checkbox_unselected, R.id.btn_sendcomment, layout_goodscomment, R.id.layout_middel_comment, R.id.layout_bad_comment, R.id.img_goods, R.id.img_middle, R.id.img_bad})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.img_news:
                finish();
                break;
            case R.id.textView6:
                break;
            case R.id.img_shop:
                break;
            case R.id.edit_comment:
                break;
            case R.id.img_checkbox_unselected:
                break;
            case R.id.btn_sendcomment:
                if (TextUtils.isEmpty(editComment.getText().toString().trim())) {
                    LovelyToast.makeText(CommentChangeActivity.this, "请输入评价内容", 0, LovelyToast
                            .SUCCESS, LovelyToast.SCALE);
                }
                getSubmitData();
                break;


            case R.id.layout_goodscomment:
                comment_status = "1";
                imgGoods.setImageResource(R.mipmap.comment_selected);
                imgMiddle.setImageResource(R.mipmap.comment_unselected);
                imgBad.setImageResource(R.mipmap.comment_unselected);
                break;
            case R.id.layout_middel_comment:
                imgGoods.setImageResource(R.mipmap.comment_unselected);
                imgMiddle.setImageResource(R.mipmap.comment_selected);
                imgBad.setImageResource(R.mipmap.comment_unselected);
                comment_status = "2";
                break;
            case R.id.layout_bad_comment:
                comment_status = "3";
                imgGoods.setImageResource(R.mipmap.comment_unselected);
                imgMiddle.setImageResource(R.mipmap.comment_unselected);
                imgBad.setImageResource(R.mipmap.comment_selected);
                break;

            case R.id.img_goods:
                comment_status = "1";
                imgGoods.setImageResource(R.mipmap.comment_selected);
                imgMiddle.setImageResource(R.mipmap.comment_unselected);
                imgBad.setImageResource(R.mipmap.comment_unselected);
                break;
            case R.id.img_middle:

                comment_status = "2";
                imgGoods.setImageResource(R.mipmap.comment_unselected);
                imgMiddle.setImageResource(R.mipmap.comment_selected);
                imgBad.setImageResource(R.mipmap.comment_unselected);
                break;
            case R.id.img_bad:
                comment_status = "3";
                imgGoods.setImageResource(R.mipmap.comment_unselected);
                imgMiddle.setImageResource(R.mipmap.comment_unselected);
                imgBad.setImageResource(R.mipmap.comment_selected);
                break;
        }
    }

    public void getSubmitData() {
        new ConnSubmitCommentChange(getIntent().getStringExtra("evaluate_id"), comment_status, editComment.getText().toString(), new AsyCallBack<CommenBean>()

        {
            @Override
            public void onStart(int type) throws Exception {
                super.onStart(type);
            }

            @Override
            public void onSuccess(String toast, int type, Object o, CommenBean commenBean) throws Exception {
                super.onSuccess(toast, type, o, commenBean);
                LovelyToast.makeText(CommentChangeActivity.this, commenBean.getMessage(), 0, LovelyToast
                        .SUCCESS, LovelyToast.SCALE);
                finish();
            }

            @Override
            public void onFail(String toast, int type) throws Exception {
                super.onFail(toast, type);
            }

            @Override
            public void onEnd(String toast, int type) throws Exception {
                super.onEnd(toast, type);
            }
        }

        ).execute(CommentChangeActivity.this, false);
    }


}
